package cn.fl.ref.asspackinfo.controller;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.lionbridge.center.dto.UserDTO;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapPayeeInfoQueryCondition;
import cn.fl.capital.service.ICapPayeeInfoService;
import cn.fl.capital.vo.CapPayeeInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.ProjectUtils;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.condition.PrjPrdPaySchMQueryCondition;
import cn.fl.project.constant.PrjPrdDtlConstant;
import cn.fl.project.dto.PrjPrdDtlDTO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.service.IPrjPrdPaySchMService;
import cn.fl.project.service.IProjectApiService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.project.vo.PrjPrdPaySchMVO;
import cn.fl.ref.asspackinfo.service.IAssPackInfoService;
import cn.fl.ref.asspackinfo.transform.AssPackInfoVOTransform;
import cn.fl.ref.asspackinfo.transform.AssPackListVOTransform;
import cn.fl.ref.asspackinfo.vo.AssPackInfoVO;
import cn.fl.ref.asspackinfo.vo.AssPackListVO;
import cn.fl.ref.asspackinfo.vo.AssPackOccupyDetailVO;
import cn.fl.ref.asspackinfo.vo.FncPrjPayRltvInfoReplaceVO;
import cn.fl.ref.asspackinfo.vo.RecordReplaceAssPackVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysRegionService;
import cn.fl.system.vo.SysRegionVO;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.ref.asspackinfo.condition.AssPackInfoQueryCondition;
import fl.ref.asspackinfo.condition.AssPackInfoReplaceQueryCondition;
import fl.ref.asspackinfo.constant.AssPackInfoConstant;
import fl.ref.asspackinfo.dto.AssPackInfoDTO;
import fl.ref.asspackinfo.dto.AssPackInfoReplaceDTO;
import fl.ref.asspackinfo.dto.AssPackListDTO;
import fl.ref.asspackinfo.dto.FncPrjPayRltvInfo2DTO;

/**
 * 	融资筛选
 * @author mrzhang
 *
 */
@Controller
@RequestMapping("/ass/asspackinfo")
public class AssPackInfoController extends BaseController{
	
	private static final Logger logger = LoggerFactory.getLogger(AssPackInfoController.class);
	
	@Autowired
	private IAssPackInfoService assPackInfoService;
	@Autowired
	private IPrjPrdPaySchMService prjPrdPaySchMService;
	/**
     * 产品服务
     */
    @Autowired
    private IProjectApiService projectApiService ;
    @Autowired
	private ICapPayeeInfoService capPayeeInfoService;//付款收款方信息表
    @Autowired
    private IPrjPrdDtlService prjPrdDtlService;
    @Autowired
    private IPrjBscInfoService prjBscInfoService;
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;
    @Autowired
	private ISysRegionService sysRegionService;
    
	/**
	 * 跳转到融资筛选列表页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response){
		logger.info("加载融资筛选列表页面.");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoList");
		//获取资产包id
		String id = request.getParameter("id");
		view.addObject("id", id);
		view.addObject("flag", "0");
		view.addObject("prjid", request.getParameter("prjid"));
		
		//获取融资基数数据字典信息
		List<KeyValueVO> fncCrdnltList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_FNC_CRDNLT);
		view.addObject("fncCrdnltList", fncCrdnltList);
		//获取客户类型数据字典信息
		List<KeyValueVO> cstTypCdList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_CST_TYPE_CD);
		view.addObject("cstTypCdList", cstTypCdList);
		//获取所属事业部数据字典信息
//		List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
//		view.addObject("buOrgCdList", buOrgCdList);
		//是／否
		List<KeyValueVO> isMortgageList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_IS_MORTGAGE);
		view.addObject("isMortgageList", isMortgageList);
		AssPackInfoVO infoVO = new AssPackInfoVO();
		if(StringUtils.isNotEmpty(id)){
			infoVO = this.assPackInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			infoVO.setPlanStdt(DateUtils.formatDateToString(infoVO.getStdt(), DateUtils.YYYY_MM_DD));
			infoVO.setPlanEddt(DateUtils.formatDateToString(infoVO.getEddt(), DateUtils.YYYY_MM_DD));
			infoVO.setFlDateBegin(DateUtils.formatDateToString(infoVO.getFlDateB(), DateUtils.YYYY_MM_DD));
			infoVO.setFlDateEnd(DateUtils.formatDateToString(infoVO.getFlDateE(), DateUtils.YYYY_MM_DD));
		}
		view.addObject("infoVO", infoVO);
		return view;
	}
	
	/**
	 * 初始化查询列表
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String flag = request.getParameter("flag");
		if(flag.equals("0")){//
			List<AssPackListVO> listVO = new ArrayList<AssPackListVO>();
			ListPageVO<AssPackListVO> listPage = new ListPageVO<AssPackListVO>(listVO,0);
			return listPage;
		}
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");								
		String fncCrdnlt = request.getParameter("fncCrdnlt");		//融资基数
		String stdt = request.getParameter("stdt");			//计划融资时间开始
		String eddt = request.getParameter("eddt");			//计划融资时间结束
		String cstTypCd = request.getParameter("cstTypCd");			//客户类型
		String buOrgCd = request.getParameter("buOrgCd");			//所属事业部
		String isMortgage = request.getParameter("isMortgage");		//是否办理抵押
		String isInsurance = request.getParameter("isInsurance");		//是否有保险
		String leaseTermMinQ = request.getParameter("leaseTermMinQ");	//租赁期数开始
		String leaseTermMaxQ = request.getParameter("leaseTermMaxQ");	//租赁期数结束
		String surplusLeaseTermMinQ = request.getParameter("surplusLeaseTermMinQ");		//剩余租赁期数开始
		String surplusLeaseTermMaxQ = request.getParameter("surplusLeaseTermMaxQ");		//剩余租赁期数结束
		String stDtQ = request.getParameter("stDtQ");		//起租日期开始
		String edDtQ = request.getParameter("edDtQ");		//起租日期结束
		String ovdDaysMin = request.getParameter("ovdDaysMin");		//逾期天数开始
		String ovdDaysMax = request.getParameter("ovdDaysMax");		//逾期天数结束
		String financingAmount = request.getParameter("financingAmount");		//融资金额
		//String paySchCds = request.getParameter("paySchCds");		//导入EXCEL支付表编号
		String fncInsIdQ = request.getParameter("fncInsIdQ");		//资产包ID
		String financingTypeCd = request.getParameter("financingTypeCd");		//再融资状态
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		AssPackInfoQueryCondition condition = new AssPackInfoQueryCondition();
		HttpSession session = request.getSession();
		if(flag.equals("2")){//导入EXCEL支付表编号
			
			List<String> paySchCdList = (List<String>) session.getAttribute("paySchCds");
			if(paySchCdList.size() > 0){
				condition.setPaySchCdList(paySchCdList);
				//session.removeAttribute("paySchCds");
			}else{
				List<AssPackListVO> listVO = new ArrayList<AssPackListVO>();
				ListPageVO<AssPackListVO> listPage = new ListPageVO<AssPackListVO>(listVO,0);
				return listPage;
			}
		}else {
			session.removeAttribute("paySchCds");
			session.removeAttribute("oldPaySchCds");
		}
		
		if (StringUtils.isNotEmpty(fncInsIdQ)) {
			condition.setId(Long.valueOf(fncInsIdQ.trim()));
		}
		if (StringUtils.isNotEmpty(fncCrdnlt)) {
			condition.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
		}
		if (StringUtils.isNotEmpty(stdt)) {
			condition.setStdt(DateUtils.formatStringToDate(stdt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(eddt)) {
			condition.setEddt(DateUtils.formatStringToDate(eddt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(cstTypCd)) {
			condition.setCstTypCd(cstTypCd.trim());
		}
		if (StringUtils.isNotEmpty(buOrgCd)) {
			condition.setBuOrgCd(buOrgCd);
		}
		if (StringUtils.isNotEmpty(isMortgage)) {
			condition.setIsMortgage(isMortgage.trim());
		}
		if (StringUtils.isNotEmpty(isInsurance)) {
			condition.setIsInsurance(isInsurance.trim());
		}
		if (StringUtils.isNotEmpty(leaseTermMinQ)) {
			condition.setLeaseTermMinQ(Integer.parseInt(leaseTermMinQ.trim()));
		}
		if (StringUtils.isNotEmpty(leaseTermMaxQ)) {
			condition.setLeaseTermMaxQ(Integer.parseInt(leaseTermMaxQ.trim()));
		}
		if (StringUtils.isNotEmpty(surplusLeaseTermMinQ)) {
			condition.setSurplusLeaseTermMinQ(Integer.parseInt(surplusLeaseTermMinQ.trim()));
		}
		if (StringUtils.isNotEmpty(surplusLeaseTermMaxQ)) {
			condition.setSurplusLeaseTermMaxQ(Integer.parseInt(surplusLeaseTermMaxQ.trim()));
		}
		if (StringUtils.isNotEmpty(stDtQ)) {
			condition.setStDtQ(DateUtils.formatStringToDate(stDtQ, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(edDtQ)) {
			condition.setEdDtQ(DateUtils.formatStringToDate(edDtQ, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(ovdDaysMin)) {
			condition.setOvdDaysMin(Integer.parseInt(ovdDaysMin.trim()));
		}
		if (StringUtils.isNotEmpty(ovdDaysMax)) {
			condition.setOvdDaysMax(Integer.parseInt(ovdDaysMax.trim()));
		}
		if (StringUtils.isNotEmpty(financingAmount)) {
			condition.setFinancingAmount(new BigDecimal(financingAmount.trim()));
		}else{
			condition.setFinancingAmount(new BigDecimal(0));
		}
		if (StringUtils.isNotEmpty(financingTypeCd)) {
			condition.setFinancingTypeCd(assembleFinancingType(financingTypeCd));
		}
		
		condition.setIsEdit(0);
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(condition);
		
		long ct = System.currentTimeMillis();
		logger.info("查询前当前时间的毫秒数：" + ct);
		Pager resultPager = this.assPackInfoService.searchListPage(page);
		List<AssPackListDTO> dtoList = (List<AssPackListDTO>)resultPager.getResultList();
		List<AssPackListVO> voList = AssPackListVOTransform.toVOList(dtoList);
		ListPageVO<AssPackListVO> listPage = new ListPageVO<AssPackListVO>(voList,resultPager.getTotalCount());

		long ct2 = System.currentTimeMillis();
		logger.info("查询后当前时间的毫秒数：" + ct2);
		logger.info("查询使用的毫秒数：" + (ct2-ct));
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(resultPager), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 组装再融资状态类型
	 * @param financingTypeCd
	 * @return
	 */
	private String assembleFinancingType (String financingTypeCd){
		String arr [] = financingTypeCd.split(";");
		String financingType = "";
		if(arr.length == 3){
			return "";
		}else{
			for(int i = 0; i < arr.length; i++){
				financingType += arr[i].toString(); 
			}
		}
		return financingType;
	}
	
	/**
	 * 组装所属事业部
	 * @param financingTypeCd
	 * @return
	 */
//	private String assembleBuOrgCd (String buOrgCd){
//		String arr [] = buOrgCd.split(";");
//		String buOrgCds = "";
//		for(int i = 0; i < arr.length; i++){
//			if(("").equals(buOrgCds)){
//				buOrgCds = "'" + arr[i] + "'"; 
//			}else{
//				buOrgCds += ",'" + arr[i] + "'"; 
//			}
//		}
//		return buOrgCds;
//	}
	
	/**
	 * 添加资产包信息
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("添加资产包信息.");
		String mark = request.getParameter("mark");		//标示查询条件（0、添加  1、覆盖添加）
		String fncInsIdQ = request.getParameter("fncInsIdQ");		//资产包编号
		String assPackNm = request.getParameter("assPackName");		//资产包名称
		String fncCrdnlt = request.getParameter("fncCrdnlt");		//融资基数
		String stdt = request.getParameter("stdt");			//计划融资日期开始
		String eddt = request.getParameter("eddt");			//计划融资日期结束
		String cstTypCd = request.getParameter("cstTypCd");			//客户类型
		String buOrgCd = request.getParameter("buOrgCd_val");			//所属事业部
		String isMortgage = request.getParameter("isMortgage");		//是否办理抵押
		String isInsurance = request.getParameter("isInsurance");		//是否有保险
		String leaseTermMinQ = request.getParameter("leaseTermMinQ");	//租赁期数开始
		String leaseTermMaxQ = request.getParameter("leaseTermMaxQ");	//租赁期数结束
		String surplusLeaseTermMinQ = request.getParameter("surplusLeaseTermMinQ");		//剩余租赁期数开始
		String surplusLeaseTermMaxQ = request.getParameter("surplusLeaseTermMaxQ");		//剩余租赁期数结束
		String stDtQ = request.getParameter("stDtQ");		//起租日期开始
		String edDtQ = request.getParameter("edDtQ");		//起租日期结束
		String ovdDaysMin = request.getParameter("ovdDaysMin");		//逾期天数开始
		String ovdDaysMax = request.getParameter("ovdDaysMax");		//逾期天数结束
		String payRltvInfo = request.getParameter("payRltvInfo");	//融资筛选出的支付表id
		String termB = request.getParameter("termB");	//融资筛选出的支付明细表期数起始
		String termE = request.getParameter("termE");	//融资筛选出的支付明细表期数结束
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		try {
			//验证参数
			if(StringUtils.isEmpty(fncCrdnlt)){//融资基数
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"融资基数不能为空!");
			}
			if(StringUtils.isEmpty(stdt)){//计划融资日期开始
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"计划融资日期不能为空!");
			}
//			if(StringUtils.isEmpty(payRltvInfo)){//融资筛选出的支付表id
//				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"融资筛选列表不能为空!");
//			}
			AssPackInfoVO vo = new AssPackInfoVO();
			if(StringUtils.isNotEmpty(fncInsIdQ)){//资产包编号
				vo.setId(Long.valueOf(fncInsIdQ.trim()));
			}
			if(StringUtils.isNotEmpty(assPackNm)){//资产包名称
				vo.setAssPackNm(assPackNm.trim());
			}
			vo.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
			if(StringUtils.isNotEmpty(stdt)){//计划融资日期开始
				vo.setStdt(DateUtils.formatStringToDate(stdt, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(eddt)){//计划融资日期结束
				vo.setEddt(DateUtils.formatStringToDate(eddt, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(cstTypCd)){//客户类型
				vo.setCstTypCd(Integer.parseInt(cstTypCd.trim()));
			}
			if(StringUtils.isNotEmpty(buOrgCd)){//所属事业部
				vo.setBuOrgCd(buOrgCd.trim());
			}
			if(StringUtils.isNotEmpty(isMortgage)){//是否办理抵押
				vo.setIsMgt(Integer.parseInt(isMortgage.trim()));
			}
			if(StringUtils.isNotEmpty(isInsurance)){//是否有保险
				vo.setIsInsure(Integer.parseInt(isInsurance.trim()));
			}
			if(StringUtils.isNotEmpty(leaseTermMinQ)){//租赁期数开始
				vo.setLeaTermB(Integer.parseInt(leaseTermMinQ.trim()));
			}
			if(StringUtils.isNotEmpty(leaseTermMaxQ)){//租赁期数结束
				vo.setLeaTermE(Integer.parseInt(leaseTermMaxQ.trim()));
			}
			if(StringUtils.isNotEmpty(surplusLeaseTermMinQ)){//剩余租赁期数开始
				vo.setReLeaTermB(Integer.parseInt(surplusLeaseTermMinQ.trim()));
			}
			if(StringUtils.isNotEmpty(surplusLeaseTermMaxQ)){//剩余租赁期数结束
				vo.setReLeaTermE(Integer.parseInt(surplusLeaseTermMaxQ.trim()));
			}
			if(StringUtils.isNotEmpty(stDtQ)){//起租日期开始
				vo.setFlDateB(DateUtils.formatStringToDate(stDtQ, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(edDtQ)){//起租日期结束
				vo.setFlDateE(DateUtils.formatStringToDate(edDtQ, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(ovdDaysMin)){//逾期天数开始
				vo.setOdDateB(Integer.parseInt(ovdDaysMin.trim()));
			}
			if(StringUtils.isNotEmpty(ovdDaysMax)){//逾期天数结束
				vo.setOdDateE(Integer.parseInt(ovdDaysMax.trim()));
			}
			vo.setIsDel(BaseConstant.IS_YESNO_NO);
			vo.setIsValid(BaseConstant.IS_YESNO_YES);
			vo.setRepSt(0);
			//旧支付表获取
			HttpSession session = request.getSession();
			List<String> oldPaySchCds = (List<String>) session.getAttribute("oldPaySchCds");
			boolean bool = this.assPackInfoService.add(vo,payRltvInfo,termB,termE,mark,oldPaySchCds);
			if(bool){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("新增成功!");
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("新增失败!");
			}
			BaseLogUtils.info(logger, "add", "新增数据成功", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "add", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 时间：2018-10-15
	 * 添加全部资产包信息by JL
	 */
	@RequestMapping(value = "/addAllAssPackInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object addAllAssPackInfo(HttpServletRequest request, HttpServletResponse response) throws Exception{
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		String flag = request.getParameter("flag");
		if(flag.equals("0")){//防止网络延迟，用户多次点击，造成数据冗余
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请勿多次点击[新增全部]按钮！");
			return result;
		}
		String mark = request.getParameter("mark");		//标示查询条件（0、添加  1、覆盖添加）
		String fncInsIdQ = request.getParameter("fncInsIdQ");		//资产包编号
		String assPackNm = request.getParameter("assPackName");		//资产包名称
		String fncCrdnlt = request.getParameter("fncCrdnlt");		//融资基数
		String stdt = request.getParameter("stdt");			//计划融资日期开始
		String eddt = request.getParameter("eddt");			//计划融资日期结束
		String cstTypCd = request.getParameter("cstTypCd");			//客户类型
		String buOrgCd = request.getParameter("buOrgCd_val");			//所属事业部
		String isMortgage = request.getParameter("isMortgage");		//是否办理抵押
		String isInsurance = request.getParameter("isInsurance");		//是否有保险
		String leaseTermMinQ = request.getParameter("leaseTermMinQ");	//租赁期数开始
		String leaseTermMaxQ = request.getParameter("leaseTermMaxQ");	//租赁期数结束
		String surplusLeaseTermMinQ = request.getParameter("surplusLeaseTermMinQ");		//剩余租赁期数开始
		String surplusLeaseTermMaxQ = request.getParameter("surplusLeaseTermMaxQ");		//剩余租赁期数结束
		String stDtQ = request.getParameter("stDtQ");		//起租日期开始
		String edDtQ = request.getParameter("edDtQ");		//起租日期结束
		String ovdDaysMin = request.getParameter("ovdDaysMin");		//逾期天数开始
		String ovdDaysMax = request.getParameter("ovdDaysMax");		//逾期天数结束
		String financingAmount = request.getParameter("financingAmount");		//融资金额
		String financingTypeCd = request.getParameter("financingTypeCd_val");	//再融资状态
		
		//=================================查询所有符合条件的资产列表数据 begin=================================//
		HttpSession session = request.getSession();
		AssPackInfoQueryCondition condition = new AssPackInfoQueryCondition();
		//非空条件-融资基数和计划融资日期
		if (StringUtils.isNotEmpty(fncCrdnlt)) {
			condition.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
		}
		if (StringUtils.isNotEmpty(stdt)) {
			condition.setStdt(DateUtils.formatStringToDate(stdt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(eddt)) {
			condition.setEddt(DateUtils.formatStringToDate(eddt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(financingAmount)) {
			condition.setFinancingAmount(new BigDecimal(financingAmount.trim()));
		}else{
			condition.setFinancingAmount(new BigDecimal(0));
		}
		if(flag.equals("1")){//针对按照查询条件新增全部
			if (StringUtils.isNotEmpty(fncInsIdQ)) {
				condition.setId(Long.valueOf(fncInsIdQ.trim()));
			}
			if (StringUtils.isNotEmpty(cstTypCd)) {
				condition.setCstTypCd(cstTypCd.trim());
			}
			if (StringUtils.isNotEmpty(buOrgCd)) {
				condition.setBuOrgCd(buOrgCd);
			}
			if (StringUtils.isNotEmpty(isMortgage)) {
				condition.setIsMortgage(isMortgage.trim());
			}
			if (StringUtils.isNotEmpty(isInsurance)) {
				condition.setIsInsurance(isInsurance.trim());
			}
			if (StringUtils.isNotEmpty(leaseTermMinQ)) {
				condition.setLeaseTermMinQ(Integer.parseInt(leaseTermMinQ.trim()));
			}
			if (StringUtils.isNotEmpty(leaseTermMaxQ)) {
				condition.setLeaseTermMaxQ(Integer.parseInt(leaseTermMaxQ.trim()));
			}
			if (StringUtils.isNotEmpty(surplusLeaseTermMinQ)) {
				condition.setSurplusLeaseTermMinQ(Integer.parseInt(surplusLeaseTermMinQ.trim()));
			}
			if (StringUtils.isNotEmpty(surplusLeaseTermMaxQ)) {
				condition.setSurplusLeaseTermMaxQ(Integer.parseInt(surplusLeaseTermMaxQ.trim()));
			}
			if (StringUtils.isNotEmpty(stDtQ)) {
				condition.setStDtQ(DateUtils.formatStringToDate(stDtQ, DateUtils.YYYY_MM_DD));
			}
			if (StringUtils.isNotEmpty(edDtQ)) {
				condition.setEdDtQ(DateUtils.formatStringToDate(edDtQ, DateUtils.YYYY_MM_DD));
			}
			if (StringUtils.isNotEmpty(ovdDaysMin)) {
				condition.setOvdDaysMin(Integer.parseInt(ovdDaysMin.trim()));
			}
			if (StringUtils.isNotEmpty(ovdDaysMax)) {
				condition.setOvdDaysMax(Integer.parseInt(ovdDaysMax.trim()));
			}
		}else if(flag.equals("2")){//导入EXCEL支付表编号-针对导入后新增全部
			List<String> paySchCdList = (List<String>) session.getAttribute("paySchCds");
			if(paySchCdList.size() > 0){
				condition.setPaySchCdList(paySchCdList);
			}
		}
		//已占用资产不允许新增
		if (StringUtils.isNotEmpty(financingTypeCd)) {
			//去除已占用的资产信息
			financingTypeCd = financingTypeCd.replace("3","");
			if(StringUtils.isNotEmpty(financingTypeCd)){
				condition.setFinancingTypeCd(assembleFinancingType(financingTypeCd));
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("已占用资产无法新增!新增失败！");
				return result;
			}
		}else{
			//未占用和预占用
			condition.setFinancingTypeCd("12");
		}
		condition.setIsEdit(0);
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		List<AssPackListDTO> dtoList = this.assPackInfoService.searchList(condition);
		BaseLogUtils.info(logger, "addAllAssPackInfo", "查询资产条件信息. condition:" + JSONObject.toJSONString(condition), CurrentThreadContext.getCurrentUserName());
		BaseLogUtils.info(logger, "addAllAssPackInfo", "待插入的资产数据总条数:" + dtoList.size(), CurrentThreadContext.getCurrentUserName());
		//=================================查询所有符合条件的资产列表数据 end=================================//
		
		//====================================遍历资产列表数据 begin====================================//
		StringBuffer payRltvInfo = new StringBuffer();	//融资筛选出的支付表id
		StringBuffer termB = new StringBuffer();	//融资筛选出的支付明细表期数起始
		StringBuffer termE = new StringBuffer();	//融资筛选出的支付明细表期数结束
		if(CollectionUtils.isNotEmpty(dtoList)){
			for (AssPackListDTO dto : dtoList) {
				if(dto.getId() != null){
					payRltvInfo.append(dto.getId());
					payRltvInfo.append(",");
				}
				if(dto.getMinPd() != null){
					termB.append(dto.getMinPd());
					termB.append(",");
				}
				if(dto.getMaxPd() != null){
					termE.append(dto.getMaxPd());
					termE.append(",");
				}
			}
			BaseLogUtils.info(logger, "addAllAssPackInfo", "[payRltvInfo="+payRltvInfo.toString()+"],[termB="+termB.toString()+"],[termE="+termE.toString()+"]", CurrentThreadContext.getCurrentUserName());
		}else{
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("无对应资产信息，新增失败!");
			return result;
		}
		//======================================遍历资产列表数据 end======================================//
		try {
			//验证参数
			if(StringUtils.isEmpty(fncCrdnlt)){//融资基数
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"融资基数不能为空!");
			}
			if(StringUtils.isEmpty(stdt)){//计划融资日期开始
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"计划融资日期不能为空!");
			}
//			if(StringUtils.isEmpty(payRltvInfo)){//融资筛选出的支付表id
//				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"融资筛选列表不能为空!");
//			}
			AssPackInfoVO vo = new AssPackInfoVO();
			if(StringUtils.isNotEmpty(fncInsIdQ)){//资产包编号
				vo.setId(Long.valueOf(fncInsIdQ.trim()));
			}
			if(StringUtils.isNotEmpty(assPackNm)){//资产包名称
				vo.setAssPackNm(assPackNm.trim());
			}
			vo.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
			if(StringUtils.isNotEmpty(stdt)){//计划融资日期开始
				vo.setStdt(DateUtils.formatStringToDate(stdt, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(eddt)){//计划融资日期结束
				vo.setEddt(DateUtils.formatStringToDate(eddt, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(cstTypCd)){//客户类型
				vo.setCstTypCd(Integer.parseInt(cstTypCd.trim()));
			}
			if(StringUtils.isNotEmpty(buOrgCd)){//所属事业部
				vo.setBuOrgCd(buOrgCd.trim());
			}
			if(StringUtils.isNotEmpty(isMortgage)){//是否办理抵押
				vo.setIsMgt(Integer.parseInt(isMortgage.trim()));
			}
			if(StringUtils.isNotEmpty(isInsurance)){//是否有保险
				vo.setIsInsure(Integer.parseInt(isInsurance.trim()));
			}
			if(StringUtils.isNotEmpty(leaseTermMinQ)){//租赁期数开始
				vo.setLeaTermB(Integer.parseInt(leaseTermMinQ.trim()));
			}
			if(StringUtils.isNotEmpty(leaseTermMaxQ)){//租赁期数结束
				vo.setLeaTermE(Integer.parseInt(leaseTermMaxQ.trim()));
			}
			if(StringUtils.isNotEmpty(surplusLeaseTermMinQ)){//剩余租赁期数开始
				vo.setReLeaTermB(Integer.parseInt(surplusLeaseTermMinQ.trim()));
			}
			if(StringUtils.isNotEmpty(surplusLeaseTermMaxQ)){//剩余租赁期数结束
				vo.setReLeaTermE(Integer.parseInt(surplusLeaseTermMaxQ.trim()));
			}
			if(StringUtils.isNotEmpty(stDtQ)){//起租日期开始
				vo.setFlDateB(DateUtils.formatStringToDate(stDtQ, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(edDtQ)){//起租日期结束
				vo.setFlDateE(DateUtils.formatStringToDate(edDtQ, DateUtils.YYYY_MM_DD));
			}
			if(StringUtils.isNotEmpty(ovdDaysMin)){//逾期天数开始
				vo.setOdDateB(Integer.parseInt(ovdDaysMin.trim()));
			}
			if(StringUtils.isNotEmpty(ovdDaysMax)){//逾期天数结束
				vo.setOdDateE(Integer.parseInt(ovdDaysMax.trim()));
			}
			vo.setIsDel(BaseConstant.IS_YESNO_NO);
			vo.setIsValid(BaseConstant.IS_YESNO_YES);
			vo.setRepSt(0);
			//旧支付表获取
			List<String> oldPaySchCds = (List<String>) session.getAttribute("oldPaySchCds");
			boolean bool = this.assPackInfoService.add(vo,payRltvInfo.toString(),termB.toString(),termE.toString(),mark,oldPaySchCds);
			if(bool){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("新增成功!");
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("新增失败!");
			}
			BaseLogUtils.info(logger, "addAllAssPackInfo", "新增数据成功", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "addAllAssPackInfo", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "addAllAssPackInfo", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 跳转到资产包列表页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toAssPackInfoPage.do", method = {RequestMethod.GET})
	public ModelAndView toAssPackInfoPage(HttpServletRequest request, HttpServletResponse response){
		logger.info("资产包列表页面.");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoListView");
		//获取融资基数数据字典信息
		List<KeyValueVO> fncCrdnltList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_FNC_CRDNLT);
		view.addObject("fncCrdnltList", fncCrdnltList);
		//获取客户类型数据字典信息
		List<KeyValueVO> cstTypCdList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_CST_TYPE_CD);
		view.addObject("cstTypCdList", cstTypCdList);
		//获取所属事业部数据字典信息
		List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
		view.addObject("buOrgCdList", buOrgCdList);
		//是／否
		List<KeyValueVO> isMortgageList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_IS_MORTGAGE);
		view.addObject("isMortgageList", isMortgageList);
		return view;
	}
	
	/**
	 * 初始化资产包查询列表
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initPackInfoList.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object initPackInfoList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");								
		String fncCrdnlt = request.getParameter("fncCrdnlt");		//融资基数
		String cstTypCd = request.getParameter("cstTypCd");			//客户类型
		String buOrgCd = request.getParameter("buOrgCd");			//所属事业部
		String isMortgage = request.getParameter("isMortgage");		//是否办理抵押
		String isInsurance = request.getParameter("isInsurance");		//是否有保险
		String leaseTermMinQ = request.getParameter("leaseTermMinQ");	//租赁期数开始
		String leaseTermMaxQ = request.getParameter("leaseTermMaxQ");	//租赁期数结束
		String surplusLeaseTermMinQ = request.getParameter("surplusLeaseTermMinQ");		//剩余租赁期数开始
		String surplusLeaseTermMaxQ = request.getParameter("surplusLeaseTermMaxQ");		//剩余租赁期数结束
		String ovdDaysMin = request.getParameter("ovdDaysMin");		//逾期天数开始
		String ovdDaysMax = request.getParameter("ovdDaysMax");		//逾期天数结束
		String assPackNm = request.getParameter("assPackNm");		//资产包名称
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		AssPackInfoQueryCondition condition = new AssPackInfoQueryCondition();
		if (StringUtils.isNotEmpty(assPackNm)) {
			condition.setAssPackNm(assPackNm.trim());
		}
		if (StringUtils.isNotEmpty(fncCrdnlt)) {
			condition.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
		}
		if (StringUtils.isNotEmpty(cstTypCd)) {
			condition.setCstTypCd(cstTypCd.trim());
		}
		if (StringUtils.isNotEmpty(buOrgCd)) {
			condition.setBuOrgCd(buOrgCd);
		}
		if (StringUtils.isNotEmpty(isMortgage)) {
			condition.setIsMortgage(isMortgage.trim());
		}
		if (StringUtils.isNotEmpty(isInsurance)) {
			condition.setIsInsurance(isInsurance.trim());
		}
		if (StringUtils.isNotEmpty(leaseTermMinQ)) {
			condition.setLeaseTermMinQ(Integer.parseInt(leaseTermMinQ.trim()));
		}
		if (StringUtils.isNotEmpty(leaseTermMaxQ)) {
			condition.setLeaseTermMaxQ(Integer.parseInt(leaseTermMaxQ.trim()));
		}
		if (StringUtils.isNotEmpty(surplusLeaseTermMinQ)) {
			condition.setSurplusLeaseTermMinQ(Integer.parseInt(surplusLeaseTermMinQ.trim()));
		}
		if (StringUtils.isNotEmpty(surplusLeaseTermMaxQ)) {
			condition.setSurplusLeaseTermMaxQ(Integer.parseInt(surplusLeaseTermMaxQ.trim()));
		}
		if (StringUtils.isNotEmpty(ovdDaysMin)) {
			condition.setOvdDaysMin(Integer.parseInt(ovdDaysMin.trim()));
		}
		if (StringUtils.isNotEmpty(ovdDaysMax)) {
			condition.setOvdDaysMax(Integer.parseInt(ovdDaysMax.trim()));
		}
		String paySchNo = request.getParameter("paySchNo");		//支付表号REQ-3699
		if (StringUtils.isNotEmpty(paySchNo)) {
			condition.setPaySchNo(paySchNo);
		}
		
		String prjFlag = request.getParameter("prjFlag");		//项目关联标识
		if (StringUtils.isNotEmpty(prjFlag)) {
			condition.setPrjFlag(prjFlag);
		}
		//外部机构资产包菜单safeFlag=101 REQ-3825
		String safeFlag = request.getParameter("safeFlag");		//支付表号REQ-3699
		//REQ-3345获取当前登录用户名（登录账号）
		String currentUserNm = "";
		UserDTO sysUsrDTO = (UserDTO)CurrentThreadContext.getValue(CurrentThreadContext.CURRENT_USER_INFO);
		if(null != sysUsrDTO){
			currentUserNm = sysUsrDTO.getUsrNm();
		}
		//判断当前登录
		if (StringUtils.isNotEmpty(currentUserNm)) {
			//查询当前登录用户角色名称-判断是否为"外部机构"
			Object object = CurrentThreadContext.getValue(CurrentThreadContext.CURRENT_ROLE_NM);
			if(null != object){
				String currentRoleNm = (String)object;
				//非[外部机构]人员和系统管理员不用设置此条件
				if("外部机构".equals(currentRoleNm) && !"admin".equals(currentUserNm)){
					condition.setInsUser(currentUserNm); //融资机构人员
				}
				BaseLogUtils.info(logger, "initPackInfoList", "[外部机构资产包管理]-当前登录用户角色名称：" + currentRoleNm, CurrentThreadContext.getCurrentUserName());
			}
		}else{
			BaseLogUtils.info(logger, "initPackInfoList", "[外部机构资产包管理]-未获取到当前登录用户信息！", CurrentThreadContext.getCurrentUserName());
		}
		
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(condition);
		
		Pager resultPager = this.assPackInfoService.searchPackInfoListPage(page);
		List<AssPackInfoDTO> dtoList = (List<AssPackInfoDTO>)resultPager.getResultList();
		List<AssPackInfoVO> voList = AssPackInfoVOTransform.toVOList(dtoList);
		//外部机构资产包管理safeFlag=101 REQ-3825
		if (StringUtils.isNotEmpty(safeFlag)) {
			if("101".equals(safeFlag)) {
				setBatchQueryOverdue(voList);//逾期数据
			}
		}//end by gengchunlan 20190703
		ListPageVO<AssPackInfoVO> listPage = new ListPageVO<AssPackInfoVO>(voList,resultPager.getTotalCount());

		BaseLogUtils.info(logger, "initPackInfoList", "查询数据完成. DATA:" + JSONObject.toJSONString(resultPager), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 到资产包信息页面
	 */
	@RequestMapping(value = "/viewAssPackInfoDetail.do", method = { RequestMethod.GET})
	public ModelAndView viewAssPackInfoDetail(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String flag = request.getParameter("flag");
		String pianflag = request.getParameter("pianflag");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoListDetail");
		if ("101".equals(pianflag)) {
			//外部机构专用
			view = new ModelAndView("rfbase/asspackinfo/assPackInfoListDetail_W");
		}
		view.addObject("id", id);
		view.addObject("flag", flag);
		view.addObject("pianflag", pianflag);
		view.addObject("fncPrjId", request.getParameter("fncPrjId"));
		view.addObject("insUserFlag", request.getParameter("insUserFlag"));
		view.addObject("isDisOverdue", request.getParameter("isDisOverdue"));//是否显示逾期数据（1：是，0：否） 
		view.addObject("paySchNo", request.getParameter("paySchNo"));//支付表号 
		return view;
	}
	
	/**
	 * 到资产包修改页面
	 */
	@RequestMapping(value = "/viewAssPackInfoEdit.do", method = { RequestMethod.GET})
	public ModelAndView viewAssPackInfoEdit(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String flag = request.getParameter("flag");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoEdit");
		//获取融资基数数据字典信息
		List<KeyValueVO> fncCrdnltList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_FNC_CRDNLT);
		view.addObject("fncCrdnltList", fncCrdnltList);
		//获取客户类型数据字典信息
		List<KeyValueVO> cstTypCdList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_CST_TYPE_CD);
		view.addObject("cstTypCdList", cstTypCdList);
		//获取所属事业部数据字典信息
		List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
		view.addObject("buOrgCdList", buOrgCdList);
		//是／否
		List<KeyValueVO> isMortgageList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_IS_MORTGAGE);
		view.addObject("isMortgageList", isMortgageList);
		AssPackInfoVO infoVO = new AssPackInfoVO();
		if(StringUtils.isNotEmpty(id)){
			infoVO = this.assPackInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			infoVO.setPlanStdt(DateUtils.formatDateToString(infoVO.getStdt(), DateUtils.YYYY_MM_DD));
			infoVO.setPlanEddt(DateUtils.formatDateToString(infoVO.getEddt(), DateUtils.YYYY_MM_DD));
			infoVO.setFlDateBegin(DateUtils.formatDateToString(infoVO.getFlDateB(), DateUtils.YYYY_MM_DD));
			infoVO.setFlDateEnd(DateUtils.formatDateToString(infoVO.getFlDateE(), DateUtils.YYYY_MM_DD));
		}
		view.addObject("infoVO", infoVO);
		view.addObject("id", id);
		view.addObject("flag", flag);
		return view;
	}
	
	/**
	 * 根据id查询资产包
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id").trim();
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功!");
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资产包id不能为空!");
		}
		AssPackInfoVO vo = new AssPackInfoVO();
		try {
			vo = this.assPackInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			vo.setPlanStdt(DateUtils.formatDateToString(vo.getStdt(), DateUtils.YYYY_MM_DD));
			vo.setPlanEddt(DateUtils.formatDateToString(vo.getEddt(), DateUtils.YYYY_MM_DD));
			vo.setFlDateBegin(DateUtils.formatDateToString(vo.getFlDateB(), DateUtils.YYYY_MM_DD));
			vo.setFlDateEnd(DateUtils.formatDateToString(vo.getFlDateE(), DateUtils.YYYY_MM_DD));
			result.setData(vo);
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误!");
			BaseLogUtils.error(logger, "getById", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 根据id查询资产包和支付表关联信息
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/fncPrjPayRltvInfo.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object fncPrjPayRltvInfo(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String id = request.getParameter("id");			//资产包id
		String fncCrdnlt = request.getParameter("fncCrdnlt");		//融资基数
		String stdt = request.getParameter("stdt");			//计划融资日期开始时间
		String eddt = request.getParameter("eddt");			//计划融资日期结束时间
		String cstTypCd = request.getParameter("cstTypCd");			//客户类型
		String buOrgCd = request.getParameter("buOrgCd");			//所属事业部
		String isMortgage = request.getParameter("isMortgage");		//是否办理抵押
		String isInsurance = request.getParameter("isInsurance");		//是否有保险
		String leaseTermMinQ = request.getParameter("leaseTermMinQ");	//租赁期数开始
		String leaseTermMaxQ = request.getParameter("leaseTermMaxQ");	//租赁期数结束
		String surplusLeaseTermMinQ = request.getParameter("surplusLeaseTermMinQ");		//剩余租赁期数开始
		String surplusLeaseTermMaxQ = request.getParameter("surplusLeaseTermMaxQ");		//剩余租赁期数结束
		String stDtQ = request.getParameter("stDtQ");		//起租日期开始
		String edDtQ = request.getParameter("edDtQ");		//起租日期结束
		String ovdDaysMin = request.getParameter("ovdDaysMin");		//逾期天数开始
		String ovdDaysMax = request.getParameter("ovdDaysMax");		//逾期天数结束
		String paySchNo = request.getParameter("paySchNo");		//支付表号
		
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资产包id不能为空!");
		}
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		AssPackInfoQueryCondition condition = new AssPackInfoQueryCondition();
		if (StringUtils.isNotEmpty(id)) {
			condition.setId(Long.valueOf(id.trim()));
			condition.setIsEdit(1);
		}
		if (StringUtils.isNotEmpty(fncCrdnlt)) {
			condition.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
		}
		if (StringUtils.isNotEmpty(stdt)) {
			condition.setStdt(DateUtils.formatStringToDate(stdt.trim(), DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(eddt)) {
			condition.setEddt(DateUtils.formatStringToDate(eddt.trim(), DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(cstTypCd)) {
			condition.setCstTypCd(cstTypCd.trim());
		}
		if (StringUtils.isNotEmpty(buOrgCd)) {
			condition.setBuOrgCd(buOrgCd);
		}
		if (StringUtils.isNotEmpty(isMortgage)) {
			condition.setIsMortgage(isMortgage.trim());
		}
		if (StringUtils.isNotEmpty(isInsurance)) {
			condition.setIsInsurance(isInsurance.trim());
		}
		if (StringUtils.isNotEmpty(leaseTermMinQ)) {
			condition.setLeaseTermMinQ(Integer.parseInt(leaseTermMinQ.trim()));
		}
		if (StringUtils.isNotEmpty(leaseTermMaxQ)) {
			condition.setLeaseTermMaxQ(Integer.parseInt(leaseTermMaxQ.trim()));
		}
		if (StringUtils.isNotEmpty(surplusLeaseTermMinQ)) {
			condition.setSurplusLeaseTermMinQ(Integer.parseInt(surplusLeaseTermMinQ.trim()));
		}
		if (StringUtils.isNotEmpty(surplusLeaseTermMaxQ)) {
			condition.setSurplusLeaseTermMaxQ(Integer.parseInt(surplusLeaseTermMaxQ.trim()));
		}
		if (StringUtils.isNotEmpty(stDtQ)) {
			condition.setStDtQ(DateUtils.formatStringToDate(stDtQ, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(edDtQ)) {
			condition.setEdDtQ(DateUtils.formatStringToDate(edDtQ, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(ovdDaysMin)) {
			condition.setOvdDaysMin(Integer.parseInt(ovdDaysMin.trim()));
		}
		if (StringUtils.isNotEmpty(ovdDaysMax)) {
			condition.setOvdDaysMax(Integer.parseInt(ovdDaysMax.trim()));
		}
		if (StringUtils.isNotEmpty(paySchNo)) {//add by gengchunlan 20190618
			condition.setPaySchNo(paySchNo);
		}//end by gengchunlan 20190618
		condition.setFinancingAmount(new BigDecimal(0));
		
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(condition);
		
		Pager resultPager = this.assPackInfoService.searchPaySchInfoList(page);
		List<AssPackListDTO> dtoList = (List<AssPackListDTO>)resultPager.getResultList();
		try {//遍历
			if(dtoList!=null && dtoList.size()>0){
				ListIterator<AssPackListDTO>  iterator = dtoList.listIterator();
		        while (iterator.hasNext()) {
		        	AssPackListDTO assDto = iterator.next();
		            if(null!=assDto.getId() && !"".equals(assDto.getId())){
		            	//根据ID获取产品明细信息
		                PrjPrdDtlDTO prjPrdDtlDTO = this.projectApiService.selectPrjPrdDtlByPaySchId(String.valueOf(assDto.getId()));
						if(prjPrdDtlDTO!=null){
							assDto.setPrjPrdDtlId(prjPrdDtlDTO.getId());
							assDto.setPrjPrdId(prjPrdDtlDTO.getPrjPrdId());
							iterator.remove();
					        iterator.add(assDto);
					        //add 实际放款金额 by gengchunlan 20190619
					        CapPayeeInfoQueryCondition cpeCondition = new CapPayeeInfoQueryCondition();
							cpeCondition.setPrjPrdId(Long.valueOf(prjPrdDtlDTO.getPrjPrdId()));
							List<CapPayeeInfoVO> capPayeeInfoList = this.capPayeeInfoService.searchListByPrjPrd(cpeCondition);
							if(capPayeeInfoList!=null && capPayeeInfoList.size()>0) {
								for(CapPayeeInfoVO capee :capPayeeInfoList) {
									if(null!=capee.getPurpCd() && !"".equals(capee.getPurpCd())) {
										if("1".equals(capee.getPurpCd())) {
											assDto.setActPayAmt(capee.getActPayAmt());//实际放款金额
										}
									}
								}
							}
					       //end by gengchunlan 
						}
					}
		       }	
			}
		}catch(Exception ex){
			ex.printStackTrace();
			BaseLogUtils.error(logger, "fncPrjPayRltvInfo", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());

		}
		List<AssPackListVO> voList = AssPackListVOTransform.toVOList(dtoList);
		ListPageVO<AssPackListVO> listPage = new ListPageVO<AssPackListVO>(voList,resultPager.getTotalCount());

		BaseLogUtils.info(logger, "fncPrjPayRltvInfo", "查询数据完成. DATA:" + JSONObject.toJSONString(resultPager), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 删除资产包信息
	 */
	@RequestMapping(value = "/deletePayRltvInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object deletePayRltvInfo(HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("删除资产包信息.");
		String assPackId = request.getParameter("assPackId");	//融资筛选出的支付表id
		String payRltvInfo = request.getParameter("payRltvInfo");	//融资筛选出的支付表id
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
		try {
			boolean bool = this.assPackInfoService.deletePayRltvInfo(payRltvInfo,assPackId);
			if(bool){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("删除成功!");
				BaseLogUtils.info(logger, "deletePayRltvInfo", "删除数据成功", CurrentThreadContext.getCurrentUserName());
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("删除失败!");
				BaseLogUtils.info(logger, "deletePayRltvInfo", "删除数据失败", CurrentThreadContext.getCurrentUserName());
			}
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "deletePayRltvInfo", "删除数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("删除失败!");
			BaseLogUtils.error(logger, "deletePayRltvInfo", "删除数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 * 清空资产包信息
	 */
	@RequestMapping(value = "/deletePayRltvInfoAll.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object deletePayRltvInfoAll(HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("清空资产包信息.");
		String assPackId = request.getParameter("assPackId");	//融资筛选出的支付表id
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "删除成功!");
		if (StringUtils.isEmpty(assPackId)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键为空!");
			return result;
		}
		try {
			boolean bool = this.assPackInfoService.deletePayRltvInfoAll(Long.valueOf(assPackId));
			if(bool){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("删除成功!");
				BaseLogUtils.info(logger, "deletePayRltvInfoAll", "清空资产包信息", CurrentThreadContext.getCurrentUserName());
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("删除失败!");
				BaseLogUtils.info(logger, "deletePayRltvInfoAll", "清空数据失败", CurrentThreadContext.getCurrentUserName());
			}
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "deletePayRltvInfoAll", "清空数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("删除失败!");
			BaseLogUtils.error(logger, "deletePayRltvInfoAll", "清空数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 * 打开资产包替换页面
	 */
	@RequestMapping(value = "/replaceAssPackInfo.do", method = { RequestMethod.GET})
	public ModelAndView replaceAssPackInfo(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");		//资产包id
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoReplace");
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资产包id不能为空!");
		}
		AssPackInfoVO vo = new AssPackInfoVO();
		try {
			//获取所属事业部数据字典信息
//			List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
//			view.addObject("buOrgCdList", buOrgCdList);
			//根据资产包ID获取资产包信息
			vo = this.assPackInfoService.selectById(Long.valueOf(id), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			vo.setPlanStdt(DateUtils.formatDateToString(vo.getStdt(), DateUtils.YYYY_MM_DD));
			vo.setPlanEddt(DateUtils.formatDateToString(vo.getEddt(), DateUtils.YYYY_MM_DD));
			vo.setFlDateBegin(DateUtils.formatDateToString(vo.getFlDateB(), DateUtils.YYYY_MM_DD));
			vo.setFlDateEnd(DateUtils.formatDateToString(vo.getFlDateE(), DateUtils.YYYY_MM_DD));
			view.addObject("assPackInfo", vo);
		} catch (BaseException ex) {
			BaseLogUtils.info(logger, "replaceAssPackInfo", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			BaseLogUtils.error(logger, "replaceAssPackInfo", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return view;
	}
	
	/**
	 * 审核退回，打开资产包替换页面编辑
	 */
	@RequestMapping(value = "/goBackReplaceAssPackInfo.do", method = { RequestMethod.GET})
	public ModelAndView goBackReplaceAssPackInfo(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");		//主业务id（资产包替换记录id，表：ass_pack_info_rep）
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoReplace");
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资产包id不能为空!");
		}
		try {
			//获取所属事业部数据字典信息
//			List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
//			view.addObject("buOrgCdList", buOrgCdList);
			//根据业务ID获取资产包信息
			AssPackInfoVO vo = getbuOrgCdList(Long.valueOf(id));
			view.addObject("assPackInfo", vo);
			view.addObject("mainId", id);
		} catch (BaseException ex) {
			BaseLogUtils.info(logger, "replaceAssPackInfo", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			BaseLogUtils.error(logger, "replaceAssPackInfo", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return view;
	}
	
	/**
	 * 资产包替换初始化查询列表
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/assPackInfoInitList.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object assPackInfoInitList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");								
		String fncCrdnlt = request.getParameter("fncCrdnlt");		//融资基数
		String paySchId = request.getParameter("paySchId");		//支付表编号
		String stdt = request.getParameter("stdt");			//计划融资时间开始
		String eddt = request.getParameter("eddt");			//计划融资时间结束
		String cstNm = request.getParameter("cstNm");			//客户名称
		String buOrgCd = request.getParameter("buOrgCd");			//所属事业部
		String ovdDaysMin = request.getParameter("ovdDaysMin");		//逾期天数开始
		String ovdDaysMax = request.getParameter("ovdDaysMax");		//逾期天数结束
		String fncInsIdQ = request.getParameter("fncInsIdQ");		//资产包ID
		String isEdit = request.getParameter("isEdit");			//是否编辑
		
		String paySchId2 = request.getParameter("paySchId2");		//支付表编号
		String cstNm2 = request.getParameter("cstNm2");			//客户名称
		String buOrgCd2 = request.getParameter("buOrgCd2");			//所属事业部
		String ovdDaysMin2 = request.getParameter("ovdDaysMin2");		//逾期天数开始
		String ovdDaysMax2 = request.getParameter("ovdDaysMax2");		//逾期天数结束
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		AssPackInfoReplaceQueryCondition condition = new AssPackInfoReplaceQueryCondition();
		if (StringUtils.isNotEmpty(fncInsIdQ)) {
			condition.setId(Long.valueOf(fncInsIdQ.trim()));
		}
		if (StringUtils.isNotEmpty(fncCrdnlt)) {
			condition.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
		}
		if (StringUtils.isNotEmpty(stdt)) {
			condition.setStdt(DateUtils.formatStringToDate(stdt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(eddt)) {
			condition.setEddt(DateUtils.formatStringToDate(eddt, DateUtils.YYYY_MM_DD));
		}
		if(isEdit.trim().equals("1")){
			if (StringUtils.isNotEmpty(paySchId)) {
				condition.setPaySchId(paySchId.trim());
			}
			if (StringUtils.isNotEmpty(cstNm)) {
				condition.setCstNm(cstNm.trim());
			}
			if (StringUtils.isNotEmpty(buOrgCd)) {
				condition.setBuOrgCd(buOrgCd);
			}
			if (StringUtils.isNotEmpty(ovdDaysMin)) {
				condition.setOvdDaysMin(Integer.parseInt(ovdDaysMin.trim()));
			}
			if (StringUtils.isNotEmpty(ovdDaysMax)) {
				condition.setOvdDaysMax(Integer.parseInt(ovdDaysMax.trim()));
			}
		}else{
			if (StringUtils.isNotEmpty(paySchId2)) {
				condition.setPaySchId(paySchId2.trim());
			}
			if (StringUtils.isNotEmpty(cstNm2)) {
				condition.setCstNm(cstNm2.trim());
			}
			if (StringUtils.isNotEmpty(buOrgCd2)) {
				condition.setBuOrgCd(buOrgCd2);
			}
			if (StringUtils.isNotEmpty(ovdDaysMin2)) {
				condition.setOvdDaysMin(Integer.parseInt(ovdDaysMin2.trim()));
			}
			if (StringUtils.isNotEmpty(ovdDaysMax2)) {
				condition.setOvdDaysMax(Integer.parseInt(ovdDaysMax2.trim()));
			}
		}
		
		condition.setIsEdit(Integer.parseInt(isEdit.trim()));
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(condition);
		
		Pager resultPager = this.assPackInfoService.searchReplaceListPage(page);
		List<AssPackListDTO> dtoList = (List<AssPackListDTO>)resultPager.getResultList();
		List<AssPackListVO> voList = AssPackListVOTransform.toVOList(dtoList);
		ListPageVO<AssPackListVO> listPage = new ListPageVO<AssPackListVO>(voList,resultPager.getTotalCount());

		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(resultPager), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 资产包替换初始化查询列表
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/replaceAssPackInfoInitList.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object replaceAssPackInfoInitList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");								
		String fncCrdnlt = request.getParameter("fncCrdnlt");		//融资基数
		String stdt = request.getParameter("stdt");			//计划融资时间开始
		String eddt = request.getParameter("eddt");			//计划融资时间结束
		String paySchId = request.getParameter("paySchId2");		//支付表编号
		String cstNm = request.getParameter("cstNm2");			//客户名称
		String buOrgCd = request.getParameter("buOrgCd2");			//所属事业部
		String ovdDaysMin = request.getParameter("ovdDaysMin2");		//逾期天数开始
		String ovdDaysMax = request.getParameter("ovdDaysMax2");		//逾期天数结束
		String fncInsIdQ = request.getParameter("fncInsIdQ");		//资产包ID
		String isEdit = request.getParameter("isEdit");			//是否编辑
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		
		AssPackInfoReplaceQueryCondition condition = new AssPackInfoReplaceQueryCondition();
		if (StringUtils.isNotEmpty(fncInsIdQ)) {
			condition.setId(Long.valueOf(fncInsIdQ.trim()));
		}
		if (StringUtils.isNotEmpty(fncCrdnlt)) {
			condition.setFncCrdnlt(Integer.parseInt(fncCrdnlt.trim()));
		}
		if (StringUtils.isNotEmpty(paySchId)) {
			condition.setPaySchId(paySchId.trim());
		}
		if (StringUtils.isNotEmpty(cstNm)) {
			condition.setCstNm(cstNm.trim());
		}
		if (StringUtils.isNotEmpty(stdt)) {
			condition.setStdt(DateUtils.formatStringToDate(stdt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(eddt)) {
			condition.setEddt(DateUtils.formatStringToDate(eddt, DateUtils.YYYY_MM_DD));
		}
		if (StringUtils.isNotEmpty(buOrgCd)) {
			condition.setBuOrgCd(buOrgCd);
		}
		if (StringUtils.isNotEmpty(ovdDaysMin)) {
			condition.setOvdDaysMin(Integer.parseInt(ovdDaysMin.trim()));
		}
		if (StringUtils.isNotEmpty(ovdDaysMax)) {
			condition.setOvdDaysMax(Integer.parseInt(ovdDaysMax.trim()));
		}
		
		condition.setIsEdit(Integer.parseInt(isEdit.trim()));
		condition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		condition.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(condition);
		
		Pager resultPager = this.assPackInfoService.searchReplaceListPage(page);
		List<AssPackListDTO> dtoList = (List<AssPackListDTO>)resultPager.getResultList();
		List<AssPackListVO> voList = AssPackListVOTransform.toVOList(dtoList);
		ListPageVO<AssPackListVO> listPage = new ListPageVO<AssPackListVO>(voList,resultPager.getTotalCount());
		
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(resultPager), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 修改资产包替换记录信息
	 */
	@RequestMapping(value = "/modifyReplaceAssPackInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object modifyReplaceAssPackInfo(HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("修改资产包替换记录信息.");
		String fncInsIdQ = request.getParameter("fncInsIdQ");		//资产包编号
		String payRltvInfo = request.getParameter("payRltvInfo");	//被替换的支付表id
		String termB = request.getParameter("termB");	//被替换的支付明细表期数起始
		String termE = request.getParameter("termE");	//被替换的支付明细表期数结束
		String financingAmount = request.getParameter("financingAmount");	//被替换的支付明细表可融资金额
		String payRltvInfo2 = request.getParameter("payRltvInfo2");	//替换的支付表id
		String termB2 = request.getParameter("termB2");	//替换的支付明细表期数起始
		String termE2 = request.getParameter("termE2");	//替换的支付明细表期数结束
		String financingAmount2 = request.getParameter("financingAmount2");	//替换的支付明细表可融资金额
		String mainId = request.getParameter("mainId");	//主业务id
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		try {
//			if(StringUtils.isEmpty(payRltvInfo2)){//替换的支付表id
//				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"可替换支付表列表选项不能为空!");
//			}
			
			FncPrjPayRltvInfoReplaceVO vo = new FncPrjPayRltvInfoReplaceVO();
			if(StringUtils.isNotEmpty(fncInsIdQ)){//资产包编号
				vo.setAssPackId(Long.valueOf(fncInsIdQ.trim()));
			}
			if(StringUtils.isNotEmpty(mainId)){//资产包编号
				vo.setRepId(Long.valueOf(mainId));
			}
			vo.setCoverPayRltvInfo(payRltvInfo);
			vo.setCoverTermB(termB);
			vo.setCoverTermE(termE);
			vo.setCoverFinancingAmount(financingAmount);
			vo.setReplacePayRltvInfo(payRltvInfo2);
			vo.setReplaceTermB(termB2);
			vo.setReplaceTermE(termE2);
			vo.setReplaceFinancingAmount(financingAmount2);
			vo.setPyStcd(String.valueOf(BaseConstant.IS_YESNO_YES));
			boolean bool = this.assPackInfoService.modifyReplaceAssPackInfo(vo);
			if(bool){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("新增成功!");
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("新增失败!");
			}
			BaseLogUtils.info(logger, "add", "新增数据成功", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "add", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 跳转到添加资产包名称页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toAddPackInfo.do", method = {RequestMethod.GET})
	public ModelAndView toAddPackInfo(HttpServletRequest request, HttpServletResponse response){
		logger.info("加载添加资产包名称页面.");
		String flag = request.getParameter("flag");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/addAssPackName");
		view.addObject("flag",flag);
		return view;
	}
	
	/**
	 * 保存资产包记录信息
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addReplaceAssPackInfo.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addReplaceAssPackInfo(HttpServletRequest request, HttpServletResponse response) {
		String fncInsIdQ = request.getParameter("fncInsIdQ");		//资产包编号
		String payRltvInfo = request.getParameter("payRltvInfo");	//被替换的支付表id
		String termB = request.getParameter("termB");	//被替换的支付明细表期数起始
		String termE = request.getParameter("termE");	//被替换的支付明细表期数结束
		String financingAmount = request.getParameter("financingAmount");	//被替换的支付明细表可融资金额
		String payRltvInfo2 = request.getParameter("payRltvInfo2");	//替换的支付表id
		String termB2 = request.getParameter("termB2");	//替换的支付明细表期数起始
		String termE2 = request.getParameter("termE2");	//替换的支付明细表期数结束
		String financingAmount2 = request.getParameter("financingAmount2");	//替换的支付明细表可融资金额
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		long replaceId = 0;		//资产包记录表id
		try{
//			if(StringUtils.isEmpty(payRltvInfo2)){//替换的支付表id
//				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"可替换支付表列表选项不能为空!");
//			}
			
			FncPrjPayRltvInfoReplaceVO vo = new FncPrjPayRltvInfoReplaceVO();
			if(StringUtils.isNotEmpty(fncInsIdQ.trim())){//资产包编号
				vo.setAssPackId(Long.valueOf(fncInsIdQ.trim()));
			}
			vo.setCoverPayRltvInfo(payRltvInfo);
			vo.setCoverTermB(termB);
			vo.setCoverTermE(termE);
			vo.setCoverFinancingAmount(financingAmount);
			vo.setReplacePayRltvInfo(payRltvInfo2);
			vo.setReplaceTermB(termB2);
			vo.setReplaceTermE(termE2);
			vo.setReplaceFinancingAmount(financingAmount2);
			vo.setPyStcd(String.valueOf(BaseConstant.IS_YESNO_YES));
			replaceId = this.assPackInfoService.replaceAndAddAssPackInfo(vo);
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "add", "新增数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		if(replaceId == 0){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
		}
		result.setId(replaceId);
		return result;
	}
	/**
	 * 启动流程
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/addFlowStart.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		String replaceId = request.getParameter("replaceId");		//资产包记录表id
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(replaceId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "addFlowStart", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(AssPackInfoConstant.REF_FLOW_S_API_H);
			flowStartParamsDTO.setProcDefKey(procDefKey);
			flowStartParamsDTO.setProcDefId(procDefId);
			flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(replaceId);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(AssPackInfoConstant.FLOW_BUSINESS_TYP_ASS_PACK_INFO);//确认用不用
			flowStartParamsDTO.setModelTyp(AssPackInfoConstant.FLOW_MODEL_TYP_API);//需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、再融资资产包替换!");
			DataResultDTO dataResultDTO = this.assPackInfoService.addFlowStart(flowStartParamsDTO);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if(StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())){
	                result.setInfo("下一个节点操作人:"+flowStartedDTO.getNextOperUsrNames());
	            }else{
	                result.setInfo("流程发起成功");
	            }
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "addFlowStart", "错误[BaseException],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addFlowStart", "错误[Exception],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}
	
	/**
	 * 资产包替换记录初始化查询列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/recordReplaceAssPackInfoInitList.do", method = {RequestMethod.GET})
	@ResponseBody
	public Object recordReplaceAssPackInfoInitList(HttpServletRequest request, HttpServletResponse response) {
		String assPackId = request.getParameter("fncInsIdQ");	//资产包id
		if(StringUtils.isEmpty(assPackId)){
			return null;
		}
		List<RecordReplaceAssPackVO> recordReplaceAssPackList = this.assPackInfoService.recordReplaceAssPackInfo(Long.valueOf(assPackId.trim()));
		ListPageVO<RecordReplaceAssPackVO> listPage = new ListPageVO<RecordReplaceAssPackVO>(recordReplaceAssPackList,recordReplaceAssPackList.size());
		
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(recordReplaceAssPackList), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 打开资产包替换审核页面
	 */
	@RequestMapping(value = "/replaceAssPackToExamine.do", method = { RequestMethod.GET})
	public ModelAndView replaceAssPackToExamine(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");		//主业务id（资产包替换记录id，表：ass_pack_info_rep）
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoReplaceToExamine");
		if(StringUtils.isEmpty(id)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"业务id为空!");
		}
		try {
			//获取所属事业部数据字典信息
//			List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
//			view.addObject("buOrgCdList", buOrgCdList);
			AssPackInfoVO vo = getbuOrgCdList(Long.valueOf(id));
			view.addObject("assPackInfo", vo);
		} catch (BaseException ex) {
			BaseLogUtils.info(logger, "replaceAssPackInfo", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			BaseLogUtils.error(logger, "replaceAssPackInfo", "获取数据失败,主键[" + id + "]." + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return view;
	}
	
	/**
	 * 根据业务id获取资产包信息
	 * @param id
	 * @return
	 */
	private AssPackInfoVO getbuOrgCdList(Long id){
		AssPackInfoVO vo = new AssPackInfoVO();
		//根据业务id获取资产包替换记录
		AssPackInfoReplaceDTO assPackInfoReplace = new AssPackInfoReplaceDTO();
		assPackInfoReplace.setId(Long.valueOf(id));
		AssPackInfoReplaceDTO assPackInfoReplaceDTO = this.assPackInfoService.getAssPackInfoReplace(assPackInfoReplace);
		if(assPackInfoReplaceDTO == null){
			return vo;
		}
		//根据资产包ID获取资产包信息
		vo = this.assPackInfoService.selectById(assPackInfoReplaceDTO.getAssPackId(), CurrentThreadContext.getCurrentSysCd(),
				CurrentThreadContext.getCurrentOrgCd());
		vo.setPlanStdt(DateUtils.formatDateToString(vo.getStdt(), DateUtils.YYYY_MM_DD));
		vo.setPlanEddt(DateUtils.formatDateToString(vo.getEddt(), DateUtils.YYYY_MM_DD));
		vo.setFlDateBegin(DateUtils.formatDateToString(vo.getFlDateB(), DateUtils.YYYY_MM_DD));
		vo.setFlDateEnd(DateUtils.formatDateToString(vo.getFlDateE(), DateUtils.YYYY_MM_DD));
		
		return vo;
	}
	
	/**
	 * 上传excel并解析
	 * @param upfile
	 * @param request
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/importExcel.do",method = { RequestMethod.POST, RequestMethod.GET})  
    @ResponseBody  
    public Object importExcel( @RequestParam(value = "upfile") MultipartFile upfile,HttpServletRequest request) throws IOException{  
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "导入成功");
		if (null == upfile) { 
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("模板文件为空,请选择文件");
			BaseLogUtils.info(logger, "addFlowStart", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result; 
     
        }
		String fileName = upfile.getOriginalFilename();//report.xls 
        String[] names=fileName.split("\\.");
        if(!names[names.length-1].toLowerCase().equals("xls") && !names[names.length-1].toLowerCase().equals("xlsx")){
        	result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("上传文件必须是 xls 或者 xlsx");
			BaseLogUtils.info(logger, "addFlowStart", SysLogConstant.LOG_CMM_ENABLE_FAIL, CurrentThreadContext.getCurrentUserName());
			return result; 
        }
        InputStream fis = upfile.getInputStream();  
        
        result = this.parseExcel(fis,result);  
        //解析到的数据就可以做一些数据库的插入操作了……  
        HttpSession session = request.getSession();
        session.removeAttribute("paySchCds");
        session.setAttribute("paySchCds", result.getData());
        //把旧支付表号存入session
        List<String> oldPaySchCds=new ArrayList<String> ();
        List<String> paySchCdList=(List<String>)result.getData();
        for (int j = 0; j < paySchCdList.size(); j++) {
        	String[] codes=paySchCdList.get(j).split(",");
        	for (int i = 0; i < codes.length; i++) {
        		String code=codes[i].replaceAll("'", "");
            	
        		PrjPrdPaySchMQueryCondition condition =new PrjPrdPaySchMQueryCondition();
    			condition.setPaySchNo(code);
    			List<PrjPrdPaySchMVO>  list=prjPrdPaySchMService.searchList(condition);
    			if (list==null || list.size()<1) {
    				oldPaySchCds.add(code);
    			}
			}
			
		}
		session.setAttribute("oldPaySchCds", oldPaySchCds);
		if (oldPaySchCds.size()>0) {
			result.setId(new Long(1));
		}
       return result;
	}
	
	/**
	 * 解析读取excel里的内容
	 * @param fis
	 * @param result
	 * @return
	 */
	public DataResultVO parseExcel(InputStream fis,DataResultVO result) {
		String paySchCds = "";
		List<String> arr = new ArrayList<>();
		try {  
            HSSFWorkbook book = new HSSFWorkbook(fis);  
            HSSFSheet sheet = book.getSheetAt(0);
            int firstRow = sheet.getFirstRowNum();
            int lastRow = sheet.getLastRowNum();
            int num = 0;
            for(int i = firstRow; i < lastRow + 1; i++) {
            	HSSFCell cell = sheet.getRow(i).getCell(0) ;
            	if(cell.getStringCellValue() != null && !("").equals(cell.getStringCellValue())){
            		if(num == 999){
            			arr.add(paySchCds);
            			paySchCds = "";
            			num = 0;
            		}
            		if(cell.getStringCellValue().contains("支付表编号")){
            			continue;
            		}else{
            			num++;
            		}
            		if("".equals(paySchCds)){
            			paySchCds =  "'" + cell.getStringCellValue() + "'";
            		}else{
            			paySchCds += ",'" + cell.getStringCellValue() + "'";
            		}
            	}
            }
            if(num <= 999){
            	arr.add(paySchCds);
    			paySchCds = "";
    			num = 0;
            }
		 } catch (IOException e) {
	        	result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.error(logger, "parseExcel", "错误[Exception] -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
				e.getStackTrace();
	          
	        }  
	        result.setData(arr);
	        return result; 
	}
	
	/**
	 * 跳转到资产包占用详情页面
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/showAssPackOccupyDetail.do", method = {RequestMethod.GET})
	public ModelAndView showAssPackOccupyDetail(HttpServletRequest request, HttpServletResponse response){
		logger.info("加载资产包占用详情页面.");
		String payId = request.getParameter("payId");
		String minPd = request.getParameter("minPd");
		String maxPd = request.getParameter("maxPd");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackOccupyDetai");
		view.addObject("payId",payId);
		view.addObject("minPd",minPd);
		view.addObject("maxPd",maxPd);
		return view;
	}
	
	/**
	 * 资产包占用详情
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/assPackOccupyDetail.do", method = {RequestMethod.GET})
	@ResponseBody
	public Map<String, Object> assPackOccupyDetail(HttpServletRequest request, HttpServletResponse response) {
		String payId = request.getParameter("payId");
		String minPd = request.getParameter("minPd");
		String maxPd = request.getParameter("maxPd");
		if(StringUtils.isEmpty(payId)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"支付id为空!");
		}
		AssPackListVO vo = new AssPackListVO();
		vo.setId(Long.valueOf(payId));
		vo.setMinPd(Integer.parseInt(minPd));
		vo.setMaxPd(Integer.parseInt(maxPd));
		List<AssPackOccupyDetailVO> voList = this.assPackInfoService.getAssPackOccupyDetail(vo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("Rows", voList);
		map.put("Total", voList.size());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(voList), CurrentThreadContext.getCurrentUserName());
		return map;
	}
	
	/**
	 * 获取所属事业部
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getbuOrgCd.do", method = {RequestMethod.GET})
	@ResponseBody
	public List<KeyValueVO> getbuOrgCd(HttpServletRequest request, HttpServletResponse response) {
		//获取所属事业部数据字典信息
		List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
		return buOrgCdList;
	}
	
	/**
	 * 资产包信息复制
	 */
	@RequestMapping(value = "/copyAssPackInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object copyAssPackInfo(HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("资产包信息复制.");
		String assPackId = request.getParameter("assPackId");		//资产包id
		String assPackNm = request.getParameter("assPackNm");		//资产包名称
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		try {
			//验证参数
			if(StringUtils.isEmpty(assPackId)){//资产包id
				throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"资产包id不能为空!");
			}
			boolean bool = this.assPackInfoService.copyAssPackInfo(assPackId, assPackNm);
			if(bool){
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("复制成功!");
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("复制失败!");
			}
			BaseLogUtils.info(logger, "copyAssPackInfo", "复制数据成功", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "copyAssPackInfo", "复制数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("复制失败!");
			BaseLogUtils.error(logger, "copyAssPackInfo", "复制数据失败" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	/**
	 * 查看导入的旧支付表号
	 * @param request
	 * @param response
	 * @return
	 * 2018年2月11日 
	 * lxb
	 */
	@RequestMapping(value = "/showOldPayCode.do", method = {RequestMethod.GET})
	public ModelAndView showOldPayCode(HttpServletRequest request, HttpServletResponse response){
		logger.info("查看导入的旧支付表号页面.");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/showOldPayCode");
		//如果是已经保存的资产款包
		if (request.getParameter("id")!=null) {
			 List<FncPrjPayRltvInfo2DTO> list= this.assPackInfoService.selectOldByAssPackId(new Long(request.getParameter("id").toString()));
			 List<String> oldPaySchCds =new ArrayList<String>();
			 if (list!=null) {
				 for (int i = 0; i < list.size(); i++) {
					oldPaySchCds.add(list.get(i).getPayCode());
				 }
			 }
			 view.addObject("oldPaySchCds",oldPaySchCds);
			return view;
		}
		//如果不是导入的
		HttpSession session = request.getSession();
		List<String> paySchCdList = (List<String>) session.getAttribute("paySchCds");
		if (paySchCdList==null || paySchCdList.size()<1) {
			return view;
		}
		//如果是导入的
		List<String> oldPaySchCds = (List<String>) session.getAttribute("oldPaySchCds");
		if (oldPaySchCds!=null) {
			view.addObject("oldPaySchCds",oldPaySchCds);
			return view;
		}
		return view;
	}
	/**
	 * 跳转到资产包列表页面 菜单【资产包管理（平安信托）】
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/toSafeAssPackInfoPage.do", method = {RequestMethod.GET})
	public ModelAndView toSafeAssPackInfoPage(HttpServletRequest request, HttpServletResponse response){
		logger.info("加载融资筛选列表页面.");
		ModelAndView view = new ModelAndView("rfbase/asspackinfo/assPackInfoListView_W");
		//获取融资基数数据字典信息
		List<KeyValueVO> fncCrdnltList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_FNC_CRDNLT);
		view.addObject("fncCrdnltList", fncCrdnltList);
		//获取客户类型数据字典信息
		List<KeyValueVO> cstTypCdList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_CST_TYPE_CD);
		view.addObject("cstTypCdList", cstTypCdList);
		//获取所属事业部数据字典信息
		List<KeyValueVO> buOrgCdList = this.assPackInfoService.getCodeDescList(AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
		view.addObject("buOrgCdList", buOrgCdList);
		//是／否
		List<KeyValueVO> isMortgageList = this.assPackInfoService.getKvList(AssPackInfoConstant.ASS_PACK_INFO_IS_MORTGAGE);
		view.addObject("isMortgageList", isMortgageList);
		//平安信托safeFlag[REQ-3345扩展成外部机构标识]
		view.addObject("safeFlag","101");
		return view;
	}
	// 批量查询 逾期天数大于30天(大于90天)的支付表的逾期金额总 资产包总的敞口（剩余租金）start by gengchunlan 20190704
	private void setBatchQueryOverdue(List<AssPackInfoVO> voList) {
		
		StringBuffer assIdStr=new StringBuffer();//资产包ids集合
		String assIds="";
		try {
			if (voList != null && voList.size() > 0) {
				for (AssPackInfoVO vo : voList) {
					if (StringUtils.isNotEmpty(vo.getId())) {
						assIdStr.append(vo.getId()+",");//拼接资产包id str
				    }
				}
				BaseLogUtils.info(logger, "setBatchQueryOverdue", "voList" + JSONObject.toJSONString(voList), CurrentThreadContext.getCurrentUserName());
				if(StringUtils.isNotBlank(assIdStr.toString())) {
					assIds=assIdStr.substring(0,assIdStr.length()-1);
					List<Map<String, Object>> ovdList=assPackInfoService.getOvdAmtSumByAssPackId(assIds);// 逾期天数大于30天(大于90天的)的支付表的逾期金额总和 Map<String,Object>
					//设置ovdAmtSum3 ovdAmtSum9 surplusRent
					for (AssPackInfoVO pack : voList) {
						if (StringUtils.isNotEmpty(pack.getId())){
							//ovdAmtSum3 ovdAmtSum9
							if(ovdList!= null && ovdList.size()>0) {
								for (Map<String, Object> ovdMap : ovdList) {
									if(ovdMap!=null && null!= ovdMap.get("ASSPACKID")) {//ovdMap
										if (StringUtils.isNotEmpty(pack.getId())
												&& (pack.getId().equals(Long.parseLong(ovdMap.get("ASSPACKID").toString())) )) {
											if(null!=ovdMap.get("OVDAMTSUM9")&&!"".equals(ovdMap.get("OVDAMTSUM9"))) {
												pack.setOvdAmtSum9(ovdMap.get("OVDAMTSUM9").toString());
											}
											 if(null!=ovdMap.get("OVDAMTSUM3")&& !"".equals(ovdMap.get("OVDAMTSUM3"))) {
												pack.setOvdAmtSum3(ovdMap.get("OVDAMTSUM3").toString()); 
											}
											if(null!=ovdMap.get("FEEAMTSUM3")&& !"".equals(ovdMap.get("FEEAMTSUM3"))) {
												pack.setFeeAmtSum3(ovdMap.get("FEEAMTSUM3").toString()); 
											} 
											if(null!=ovdMap.get("FEEAMTSUM9")&& !"".equals(ovdMap.get("FEEAMTSUM9"))) {
												pack.setFeeAmtSum9(ovdMap.get("FEEAMTSUM9").toString()); 
											}  
											break;
										}
									}//ovdMap
								}
							}//end ovdAmtSum3 ovdAmtSum9
							//surplusRent
							/*
							 * if(rentList!= null && rentList.size()>0) { for (Map<String, Object> rentMap :
							 * rentList) { if(rentMap!=null && null!= rentMap.get("ASSPACKID")) {//ovdMap if
							 * (StringUtils.isNotEmpty(pack.getId()) && (pack.getId() ==
							 * Long.parseLong(rentMap.get("ASSPACKID").toString()))) {
							 * if(null!=rentMap.get("SURPLUSRENT")&&!"".equals(rentMap.get("SURPLUSRENT")))
							 * { pack.setSurplusRent(rentMap.get("SURPLUSRENT").toString()); } break; }
							 * }//ovdMap } }
							 *///end surplusRent
							//payDate提款管理 到账时间
							if(null!=pack.getTranstm() &&  StringUtils.isNotBlank(pack.getTranstm().toString())) {
								SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
								String transtm=sdf.format(pack.getTranstm());
								List<Map<String, Object>> rentList=assPackInfoService.getSurplusRentByAssPackId(pack.getId().toString(),transtm);//资产包总的敞口（* 剩余租金）
								if(rentList!=null && rentList.size()>0){
									Map<String, Object> rentMap=rentList.get(0);
									if(null!=rentMap.get("SURPLUSRENT")&&!"".equals(rentMap.get("SURPLUSRENT"))) {
										pack.setSurplusRent(rentMap.get("SURPLUSRENT").toString()); 
								     }  
								}
							}//end payDate提款管理 到账时间	
						}//end pack.getId()
							
					
					}//end 设置	
				}
			}//end voList
		
		} catch (Exception e) {
			BaseLogUtils.error(logger, "setBatchQueryOverdue", "setBatchQueryOverdue:" + e.getMessage());
			e.printStackTrace();
		}
	}//end 
	
	
	/**
	 * 跳转到抵押记录页面
	 */
	@RequestMapping("/toMortgageList.do")
	public String toMortgageList(HttpServletRequest request) {

		request.setAttribute("paySchNo", request.getParameter("paySchNo"));
		
		return "rfbase/asspackinfo/toMortgageList";
	}
	
	/**
	 * 抵押记录数据
	 */
	@RequestMapping("/mortgageList.do")
	@ResponseBody
	public Object mortgageList(HttpServletRequest request) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String paySchNo = request.getParameter("paySchNo");
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO);
		try {
			Pager page = new Pager();
			if (StringUtils.isNotEmpty(currentPage)) {
				page.setCurrentPage(Integer.parseInt(currentPage));
			}
			if (StringUtils.isNotEmpty(pageSize)) {
				page.setEveryPage(Integer.parseInt(pageSize));
			}

			if (StringUtils.isBlank(paySchNo)) {
				result.setInfo("paySchNo为空");
				return result;
			}
			
//			PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
//			qc.setPaySchNo(paySchNo);
//			List<PrjPrdPaySchMVO>  prjPrdPaySchMVOList = prjPrdPaySchMService.searchList(qc);
//			BaseLogUtils.info(logger, null, "prjPrdPaySchMVOList:" + JSONObject.toJSONString(prjPrdPaySchMVOList), CurrentThreadContext.getCurrentUserName());
//			
//			if (CollectionUtils.isEmpty(prjPrdPaySchMVOList)) {
//				result.setInfo("prjPrdPaySchMVOList为空");
//				return result;
//			}
//			
//			PrjPrdPaySchMVO prjPrdPaySchMVO = prjPrdPaySchMVOList.get(0);
//			page.setCondition(prjPrdPaySchMVO.getId());

			page.setCondition(paySchNo);
			
			page = this.assPackInfoService.mortgageList(page);
			List<Map<String, Object>> list = (List<Map<String, Object>>) page.getResultList();
			BaseLogUtils.info(logger, null, "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
			return new ListPageVO<Map<String, Object>>(list, page.getTotalCount());
		} catch (Exception e) {
			e.printStackTrace();
			BaseLogUtils.error(logger, null, "mortgageList查询失败" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
			result.setInfo("mortgageList查询失败:" + e.getMessage());
			return result;
			
		}
	}
	
	/**
	 * 支付表详情
	 */
	@RequestMapping("/paySchView.do")
	public String paySchView(HttpServletRequest request) {

		String paySchNo = request.getParameter("paySchNo");
		if (StringUtils.isNotBlank(paySchNo)) {
			
			try {
				//支付表
				PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
				qc.setPaySchNo(paySchNo);
				List<PrjPrdPaySchMVO>  prjPrdPaySchMVOList = prjPrdPaySchMService.searchList(qc);
				if (CollectionUtils.isNotEmpty(prjPrdPaySchMVOList)) {
					PrjPrdPaySchMVO prjPrdPaySchMVO = prjPrdPaySchMVOList.get(0);
					BaseLogUtils.info(logger, null, "prjPrdPaySchMVO:" + JSONObject.toJSONString(prjPrdPaySchMVO), CurrentThreadContext.getCurrentUserName());
					
					Integer period = ProjectUtils.getRentPeriod(prjPrdPaySchMVO.getLsPd().intValue(), Integer.valueOf(prjPrdPaySchMVO.getLsPdUntCd()));
					
					request.setAttribute("prjPrdPaySchMVO", prjPrdPaySchMVO);
					request.setAttribute("period", period);
				}
				
				//产品明细
				PrjPrdDtlQueryCondition qc2 = new PrjPrdDtlQueryCondition();
				qc2.setPaySchNo(paySchNo);
				List<PrjPrdDtlVO> prjPrdDtlVOList = this.prjPrdDtlService.selectList(qc2);
				if (CollectionUtils.isNotEmpty(prjPrdDtlVOList)) {
					PrjPrdDtlVO prjPrdDtlVO = prjPrdDtlVOList.get(0);
					BaseLogUtils.info(logger, null, "prjPrdDtlVO:" + JSONObject.toJSONString(prjPrdDtlVO), CurrentThreadContext.getCurrentUserName());
					request.setAttribute("prjPrdDtlVO", prjPrdDtlVO);
					
					//设置资产状态
					Map<String, String> prjPrdStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(),
							CurrentThreadContext.getCurrentOrgCd(), PrjPrdDtlConstant.CODE_PRJ_PRD_STS_CD);
					prjPrdDtlVO.setPrdStsCdNm(prjPrdStsCdMap.get(prjPrdDtlVO.getPrdStsCd()));
					
					
					//查询项目
				    PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(prjPrdDtlVO.getPrjId());
				    BaseLogUtils.info(logger, null, "prjBscInfoVO:" + JSONObject.toJSONString(prjBscInfoVO), CurrentThreadContext.getCurrentUserName());
					
				    //查询地区
				    if(prjBscInfoVO != null && StringUtils.isNotBlank(prjBscInfoVO.getRgnPrCd())) {
				    	//省
				    	SysRegionVO sysRegionVO = this.sysRegionService.getRegionByRgnCd(prjBscInfoVO.getRgnPrCd());
				        if(null != sysRegionVO && StringUtils.isNotEmpty(sysRegionVO.getRgnNm())){
				            String addr = sysRegionVO.getRgnNm();
				            
				            //市
				            List<KeyValueVO> rgnKvList = this.sysRegionService.searchRegineKVList(prjBscInfoVO.getRgnPrCd());
							for (KeyValueVO keyValueVO : rgnKvList) {
								if(prjBscInfoVO.getRgnCyCd().equals(keyValueVO.getKey()) ) {
									addr += keyValueVO.getValue();
									break;
								}
							}
//	                    BaseLogUtils.info(logger, null, "rgnKvList:" + JSONObject.toJSONString(rgnKvList), CurrentThreadContext.getCurrentUserName());
							
				            request.setAttribute("addr", addr);
				        }
				    }
				    
				    
				    request.setAttribute("prjBscInfoVO", prjBscInfoVO);
				}
			}catch (Exception e) {
				e.printStackTrace();
				BaseLogUtils.error(logger, null, "paySchView失败:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
			}
		}
		
		
		return "rfbase/asspackinfo/paySchView";
	}
	
	/**
	 * @author gengchunlan
	  *     根据支付表状态查询启用状态，当该支付表启用的是备份支付表时，返回转换后的支付表id
	 */
	@RequestMapping("/getPayIdAutoChange.do")
	@ResponseBody
	public Object getPayIdAutoChange(HttpServletRequest request) {
		String payId = request.getParameter("payId");//原支付表ID
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO);
		result.setData(payId);
		try {
			if (StringUtils.isBlank(payId)) {
				result.setInfo("payId不能为空");
				return result;
			}
			PrjPrdPaySchMVO payVO =	prjPrdPaySchMService.selectById(Long.parseLong(payId));
			BaseLogUtils.newLogger("payVO@@"+JSONObject.toJSONString(payVO)).info();//启用的支付表Id
			//IS_ENABLE	 是否启用(SYS0021):1.是 0.否
			Integer isEnable = payVO.getIsEnable();
			if(isEnable!=null && isEnable==0) {//未启用
				//根据支付表Id查询dtl_id -1系列的对应一台车 -2系列对应一台车
				PrjPrdDtlQueryCondition prjPrdDtlQc = new PrjPrdDtlQueryCondition();
				prjPrdDtlQc.setPaySchId(Long.parseLong(payId));
				List<PrjPrdDtlVO> dtlList= prjPrdDtlService.selectList(prjPrdDtlQc);
				Long diPrjPrdDtlId =0l;
				if(CollectionUtils.isNotEmpty(dtlList)){
					diPrjPrdDtlId=dtlList.get(0).getId();//* 项目产品明细ID（PRJ_PRD_DTL.ID）
				}
				 PrjPrdPaySchMQueryCondition qc = new PrjPrdPaySchMQueryCondition();
			     qc.setPrjId(payVO.getPrjId());
			     qc.setIsEnable(1);//查询启用的支付表信息
			     List<PrjPrdPaySchMVO> list = this.prjPrdPaySchMService.searchList(qc);
			     BaseLogUtils.newLogger("list@@"+JSONObject.toJSONString(list)).info();//查询启用的数据
			     if(CollectionUtils.isNotEmpty(list)){
			    	for(PrjPrdPaySchMVO mvo:list) {
			    		//查询启用的支付表Id的产品明细id,比对我司，是否是同一台车
						PrjPrdDtlQueryCondition qcc = new PrjPrdDtlQueryCondition();
						qcc.setPaySchId(mvo.getId());//启用的支付表ID
						List<PrjPrdDtlVO> enlist= prjPrdDtlService.selectList(qcc);
						if(CollectionUtils.isNotEmpty(enlist)){
							Long enPrjPrdDtlId = enlist.get(0).getId();//启用的支付表产品明细表Id
							if(diPrjPrdDtlId.equals(enPrjPrdDtlId)) {//同一台车
								result.setData(mvo.getId());
								BaseLogUtils.newLogger("mvo.getId()@@"+mvo.getId()).info();//启用的支付表Id
				    			break;
							}
						}
			    	} 
			     }
			     if(CollectionUtils.isEmpty(list)){//查询一下是否为资管
			    	 PrjPrdPaySchMQueryCondition zqc = new PrjPrdPaySchMQueryCondition();
					 zqc.setIsSqBiz(0);//是否我司业务: 0-否，1-是
				     zqc.setPrjId(payVO.getPrjId());
				     zqc.setIsEnable(1);//查询启用的支付表信息
				     List<PrjPrdPaySchMVO> zlist = this.prjPrdPaySchMService.searchList(zqc);
				     BaseLogUtils.newLogger("zlist@@@"+JSONObject.toJSONString(zlist)).info();//查询启用的数据
				     if(CollectionUtils.isNotEmpty(zlist)) {
				    	 for(PrjPrdPaySchMVO mvo:zlist) {//资方直接显示合计
				    		 result.setData(mvo.getId());
							 BaseLogUtils.newLogger("mvo.getId()@@@@"+mvo.getId()).info();//启用的支付表Id
				    		 break;
					     }  
				     }
			     }
			}
			result.setSuccess(BaseConstant.IS_YESNO_YES);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			BaseLogUtils.error(logger, null, "getPayIdAutoChange查询失败" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
			result.setInfo("getPayIdAutoChange查询失败:" + e.getMessage());
			return result;
			
		}
		BaseLogUtils.newLogger("map@@"+JSONObject.toJSONString(result)).info();//启用的支付表Id
		return result;
	}
	
	
	
	
	
	
	
}
